//
//  DetailFriedHeadView.m
//  ZITHER
//
//  Created by weixin on 2018/9/25.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "DetailFriedHeadView.h"
#import "Ugc_HomePage_VC_V3.h"
#import "UILabel+YBAttributeTextTapAction.h"
#import "TopicDetailViewController.h"

#define UILABEL_LINE_SPACE 6

@implementation DetailFriedHeadView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
        [self setMasonry];
    }
    return self;
}

-(void)setModel:(userUgcDetailModelSub *)model{
    
    _model = model;
    
    NSString *str = [NSString stringWithFormat:@"%@%@/zip",RootUrlImage,model.avatar];
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:str]];
    self.userName.text = model.nickName;
    self.time.text = [model.createTime convertCurrentTime];
    
    self.usercomment.text = model.ugcContent;
    
    if ([self.model.userId isEqualToString:kUSER_INFO_MANAGER.userId]) {
        self.userDelete.hidden = NO;
    }else{
        self.userDelete.hidden = YES;
    }

    [self setIndexCell:model.fileList.count];
    
    if (model.userSubjectTitle.length>0 ) {
        self.TopicLab.text = [NSString stringWithFormat:@"    %@",model.userSubjectTitle];
        self.TopicIcon.hidden = NO;
        [self.TopicLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.userName.mas_bottom).offset(10);
            
        }];
    }else{
        self.TopicIcon.hidden = YES;
        self.TopicLab.text = @"";
        [self.TopicLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.userName.mas_bottom).offset(0);
        }];
    }
}


-(void)setMasonry{
    
    self.userImage.backgroundColor = [UIColor randomColor];
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(20);
        make.width.height.mas_equalTo(30);
    }];
    
    //    self.userName.backgroundColor = [UIColor randomColor];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userImage.mas_centerY).offset(0);
//        make.bottom.equalTo(self.userImage).offset(0);
        make.left.equalTo(self.userImage.mas_right).offset(10);
        //        make.width.height.mas_equalTo(20);
    }];
    //    self.comment.backgroundColor = [UIColor randomColor];
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userName.mas_centerY).offset(0);
        make.left.equalTo(self.userName.mas_right).offset(10);
        //        make.bottom.equalTo(self).offset(-40);
    }];
    
    [self.userDelete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(19);
        make.top.equalTo(self.userPic.mas_bottom).offset(15);
    }];
    
    //    self.usercomment.backgroundColor = [UIColor randomColor];
    [self.usercomment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.TopicLab.mas_bottom).offset(10);
        make.left.equalTo(self.userImage).offset(0);
        make.right.equalTo(self.mas_right).offset(-20);
        
        //        make.width.height.mas_equalTo(100);
        //        make.bottom.equalTo(self).offset(-10);
    }];
    
    
    //    self.userPic.backgroundColor = [UIColor redColor];
    [self.userPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.usercomment.mas_bottom).offset(10);
        make.left.equalTo(self.userImage).offset(0);
//        make.right.equalTo(self.mas_right).offset(-20);
        make.height.mas_equalTo(0);
        make.width.mas_equalTo(((kScreenW-28)/3.0)*3);
    }];

    

    [self.labLike mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userDelete.mas_bottom).offset(50);
        make.left.equalTo(self).offset(14);
        make.height.mas_equalTo(30);
        //        make.width.height.mas_equalTo(20);
    }];
    
    //    self.btnLike.backgroundColor = [UIColor randomColor];
    [self.btnLike mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labLike.mas_centerY).offset(0);
        make.right.equalTo(self).offset(-14);
        make.width.height.mas_equalTo(30);
    }];
    
    //    self.time.backgroundColor = [UIColor randomColor];
    [self.labLikeName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labLike.mas_bottom).offset(12);
        make.right.equalTo(self).offset(-14);
        make.left.equalTo(self).offset(14);
    }];
    
    [self.commentNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labLikeName.mas_bottom).offset(50);
        make.right.equalTo(self).offset(-14);
        make.left.equalTo(self).offset(14);
        make.height.height.mas_equalTo(20);
    }];
    
    [self.commentNumBackGround mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.commentNum.mas_top).offset(-20);
        make.right.equalTo(self).offset(0);
        make.left.equalTo(self).offset(0);
        make.bottom.equalTo(self).offset(0);
    }];
    [self.TopicLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userName.mas_bottom).offset(15);
        make.left.equalTo(self.userImage).offset(0);
        make.right.equalTo(self.mas_right).offset(-20);
        
    }];
    
    [self.TopicIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.TopicLab.mas_top).offset(5);
        make.left.equalTo(self.TopicLab.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(10, 13));
    }];
}


-(void)setModelLike:(userUgcDetailModel *)modelLike{
    _modelLike = modelLike;

    
    if ([modelLike.userUgc.laudStatus isEqualToString:@"0"]) {
        self.btnLike.selected = NO;
    }else{
        self.btnLike.selected = YES;
    }
    
    if (![modelLike.userUgc.laudCount isEqualToString:@"0"]) {
        self.labLike.text = [NSString stringWithFormat:@"%@人已赞",modelLike.userUgc.laudCount] ;
    }else{
        self.labLike.text = @"暂无点赞";
    }
    
    if (![modelLike.userUgc.commentCount isEqualToString:@"0"]) {
        self.commentNum.text = [NSString stringWithFormat:@"%@条评论",modelLike.userUgc.commentCount] ;
    }else{
        self.commentNum.text = @"暂无评论";
    }
    
    NSMutableString *str = [[NSMutableString alloc]init];
    NSMutableArray *arrM = [[NSMutableArray alloc]init];
    //    for (int i =0; i<10; i++) {
//    for (int i = 0; i<modelLike.laudUserList.count; i++) {
//        NSString *str1 = [NSString stringWithFormat:@"%@  ",modelLike.laudUserList[i].nickName];
//        [str appendString:str1];
//        [arrM addObject:modelLike.laudUserList[i].nickName];
//    }

    
    [self setLabelSpace:self.labLikeName withValue:str withFont:self.labLikeName.font];
    
    @weakify(self);
    
    [self.labLikeName yb_addAttributeTapActionWithStrings:arrM tapClicked:^(NSString *string, NSRange range, NSInteger index) {
        @strongify(self);
        Ugc_HomePage_VC_V3 *vc = [[Ugc_HomePage_VC_V3 alloc]init];
        vc.userName = modelLike.laudUserList[index].nickName;
        vc.userId = modelLike.laudUserList[index].userId;
        vc.userAvatar = modelLike.laudUserList[index].avatar;
        [self.getNav pushViewController:vc animated:YES];
    }];
    //设置是否有点击效果，默认是YES
    self.labLikeName.enabledTapEffect = NO;
    //    self.labLikeName.text = str;

}


-(void)setUI{
    [self addSubview:self.userImage];
    [self addSubview:self.userName];
    [self addSubview:self.time];
    [self addSubview:self.usercomment];
    [self addSubview:self.userPic];
    [self addSubview:self.userDelete];
    
    [self addSubview:self.btnLike];
    [self addSubview:self.labLike];
    [self addSubview:self.labLikeName];
    [self addSubview:self.commentNumBackGround];
    [self addSubview:self.commentNum];
    [self addSubview:self.TopicLab];
    [self addSubview:self.TopicIcon];
}

-(void)setIndexCell:(NSInteger)indexCell
{
    _indexCell = indexCell;
    //0:带文字,不带图片 1:不带文字,带图片 2:带图片,带文字
    
    if (indexCell == 0) {
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }else if (indexCell == 1){
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo((kScreenW-28)/3.0*2);
        }];
    }else if (indexCell/4 < 1){
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(((kScreenW-28)/3.0-10));
        }];
    }else if (indexCell/7 < 1){
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(((kScreenW-28)/3.0)*2-10);
        }];
    }else{//(indexCell/3<=3)
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {

            make.height.mas_equalTo(((kScreenW-28)/3.0)*3-10);
        }];
    }
    [self layoutIfNeeded];
    [self addImage:indexCell];
    
}

-(void)addImage:(NSInteger)index{
    [self.userPic.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    if (index == 0) {
        
    }else if (index == 1){
        
        [self setPic];
        
//        CGRect rect = self.userPic.bounds;
//        rect.size.height = (kScreenW-28)/3.0*2;
//        UIImageView *imageV = [[UIImageView alloc]initWithFrame:rect];
////        [imageV setCornerRadiusWithRadius:8 isMasks:YES];
//        imageV.contentMode = 2;
//        imageV.tag = 100;
//        imageV.clipsToBounds = YES;
//        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList.firstObject];
//        [imageV sd_setImageWithURL:[NSURL URLWithString:str]];
//        imageV.backgroundColor = [UIColor randomColor];
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
//        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
//            [self showBigImage:imageV.tag];
//        }];
//        [imageV addGestureRecognizer:tap];
//        imageV.userInteractionEnabled = YES;
//        imageV.backgroundColor = [UIColor randomColor];
//        [self.userPic addSubview:imageV];
        
        
    }else if (index == 4){
        for (int i = 0; i<index; i++) {
            CGFloat imgHeight = (kScreenW-28)/3.0-10;
            UIImageView *imageV = [[UIImageView alloc]init];
            imageV.frame =  CGRectMake(i%2*(imgHeight+10), i/2*(imgHeight+10), imgHeight, imgHeight);
            imageV.tag = i+100;
            imageV.contentMode = 2;
            imageV.clipsToBounds = YES;
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList[i]];
            [imageV sd_setImageWithURL:[NSURL URLWithString:str]];
            imageV.backgroundColor = [UIColor randomColor];
            [self.userPic addSubview:imageV];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
            
            [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
                [self showBigImage:imageV.tag];
            }];
            [imageV addGestureRecognizer:tap];
            
            imageV.userInteractionEnabled = YES;

//            [imageV setCornerRadiusWithRadius:8 isMasks:YES];
            imageV.clipsToBounds = YES;
        }
    }else{
        for (int i = 0; i<index; i++) {
            CGFloat imgHeight = (kScreenW-28)/3.0-10;
            UIImageView *imageV = [[UIImageView alloc]init];
            imageV.frame =  CGRectMake(i%3*(imgHeight+10), i/3*(imgHeight+10), imgHeight, imgHeight);
            imageV.tag = i+100;
            imageV.contentMode = 2;
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList[i]];
            [imageV sd_setImageWithURL:[NSURL URLWithString:str]];
            imageV.backgroundColor = [UIColor randomColor];
            [self.userPic addSubview:imageV];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
            @weakify(self);
            
            [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
                @strongify(self);
                [self showBigImage:imageV.tag];
            }];
            [imageV addGestureRecognizer:tap];
            
            imageV.userInteractionEnabled = YES;
            //            [imageV sd_setImageWithURL:[NSURL URLWithString:arrM[i]] placeholderImage:nil];
//            [imageV setCornerRadiusWithRadius:8 isMasks:YES];
            imageV.clipsToBounds = YES;
        }
    }
}



-(UIImageView *)userImage{
    if (!_userImage) {
        _userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _userImage.contentMode = 2;
        [_userImage setCornerRadiusWithRadius:15 isMasks:YES];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        @weakify(self);
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self);
            Ugc_HomePage_VC_V3 *vc = [[Ugc_HomePage_VC_V3 alloc]init];
            vc.userName = self.model.nickName;
            vc.userId = self.model.userId;
            vc.userAvatar =  self.model.avatar;
            [self.getNav pushViewController:vc animated:YES];
        }];
        [_userImage addGestureRecognizer:tap];
        _userImage.userInteractionEnabled = YES;

    }
    return _userImage;
}


//单张图 大小+缓存
-(void)setPic{
 
    
    CGRect rect = self.userPic.bounds;
    rect.size.height = (kScreenW-28)/3.0*2;
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:rect];
    //        [imageV setCornerRadiusWithRadius:8 isMasks:YES];
    imageV.contentMode = 2;
    imageV.tag = 100;
    imageV.clipsToBounds = YES;
    imageV.backgroundColor = [UIColor randomColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        [self showBigImage:imageV.tag];
    }];
    [imageV addGestureRecognizer:tap];
    imageV.userInteractionEnabled = YES;
    [self.userPic addSubview:imageV];

    
    NSString *pic = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList.firstObject];
    
    NSString *picH = [NSString stringWithFormat:@"%@HDetail",pic];
    NSString *picW = [NSString stringWithFormat:@"%@WDetail",pic];
    
    if (![[NSUserDefaults standardUserDefaults] objectForKey:picH]) {
        //ucg_img_loding 图片背景图
        [imageV sd_setImageWithURL:[NSURL URLWithString:pic] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            //        NSLog(@"获取到图片宽和高");
            CGSize MaxSize = CGSizeMake(kScreenW-40,(kScreenW-40)/3.0*2);
//            UIImage *imgaeSize = [UIImage imageCompressFitSizeScale:image targetSize:MaxSize];
            
            CGSize Size = [UIImage getSingleSize:image.size MaxH:MaxSize.height MaxW:MaxSize.width url:pic];
            
            //        NSLog(@"size.width = %f size.height = %f",image.size.width,image.size.height);
            //        NSLog(@"size.width = %f size.height = %f",imgaeSize.size.width,imgaeSize.size.height);
            //        NSLog(@"size.width = %f size.height = %f",Size.width,Size.height);
            //
            //        NSLog(@"");
            imageV.frame = CGRectMake(0, 0, Size.width, Size.height);
            [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(Size.height);
                make.width.mas_equalTo(Size.width);
            }];
            [self layoutIfNeeded];
//            [[NSUserDefaults standardUserDefaults] setObject:@(Size.height) forKey:picH];
//            [[NSUserDefaults standardUserDefaults] setObject:@(Size.width) forKey:picW];
            //将最终的自适应的高度 本地化处理
            
        }];
        
    }else{
        
        NSString * strW = [[NSUserDefaults standardUserDefaults] objectForKey:picW];
        NSString * strH = [[NSUserDefaults standardUserDefaults] objectForKey:picH];
        CGFloat fW = [strW floatValue];
        CGFloat fH = [strH floatValue];
        
        CGSize Size = CGSizeMake(fW,fH);
        imageV.frame = CGRectMake(0, 0, Size.width, Size.height);
        [self.userPic mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(Size.height);
            make.width.mas_equalTo(Size.width);
        }];
        [self layoutIfNeeded];
        [imageV sd_setImageWithURL:[NSURL URLWithString:pic] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
    }
    
}

-(QMUILabel *)userName{
    if (!_userName) {
        _userName = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _userName.font = [UIFont systemFontOfSize:15];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        @weakify(self);
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self);
            Ugc_HomePage_VC_V3 *vc = [[Ugc_HomePage_VC_V3 alloc]init];
            vc.userName = self.model.nickName;
            vc.userId = self.model.userId;
            vc.userAvatar =  self.model.avatar;
            [self.getNav pushViewController:vc animated:YES];
        }];
        [_userName addGestureRecognizer:tap];
        _userName.userInteractionEnabled = YES;
    }
    return _userName;
}

-(QMUILabel *)time{
    if (!_time) {
        _time = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _time.font = [UIFont systemFontOfSize:13];
        _time.textColor = baseColorMedium;
    }
    return _time;
}

-(QMUIButton *)userDelete{
    if (!_userDelete) {
        _userDelete = [[QMUIButton alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        [_userDelete setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        _userDelete.titleLabel.font = [UIFont systemFontOfSize:12];
        [_userDelete setTitle:@"删除" forState:UIControlStateNormal];
        _userDelete.hidden = YES;
        @weakify(self);
        [[_userDelete rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [[serviceDefualt loaddelUserUgcUgcId:self.model.ugcId reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
                if (x.success) {
                    
                    Ugc_Detail_VC_WX *vc = (Ugc_Detail_VC_WX*)[self getViewController:[Ugc_Detail_VC_WX class]];

                    if (vc.blockDel) {
                        vc.blockDel();
                    }
                    
                    [self.getNav popViewControllerAnimated:YES];
                    [Tools showTips:@"删除成功"];
                }else{
                     [Tools showTips:x.errorInfo];
                }
            }];
        }];
    }
    return _userDelete;
}

-(QMUILabel *)usercomment{
    if (!_usercomment) {
        _usercomment = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _usercomment.numberOfLines = 0;
//        _usercomment.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
        _usercomment.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14];
        _usercomment.textColor = HexColor(0x333333);
    }
    return _usercomment;
}

-(UIView *)userPic{
    if (!_userPic) {
        _userPic = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _userPic.userInteractionEnabled = YES;
        
    }
    return _userPic;
}

-(void)showBigImage:(NSInteger)selectIndex{
    UIImageView *imageV = [self.userPic viewWithTag:selectIndex];
    // self.model.fileList[selectIndex-100];
    
    
    if (!self.imagePreviewViewController) {
        self.imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
        self.imagePreviewViewController.imagePreviewView.delegate = self;
        
        // QMUIImagePreviewViewController 对于以 window 的方式展示的情况，默认会开启手势拖拽退出预览功能。
        // 如果使用了手势拖拽，并且退出预览时需要飞到某个 rect，则需要实现这个 block，在里面自己去 exit，如果不实现这个 block，退出动画会使用 fadeOut 那种
        
    }
    
    __weak __typeof(self)weakSelf = self;
    self.imagePreviewViewController.customGestureExitBlock = ^(QMUIImagePreviewViewController *aImagePreviewViewController, QMUIZoomImageView *currentZoomImageView) {
        NSInteger index = aImagePreviewViewController.imagePreviewView.currentImageIndex;
        UIImageView *imageV1 = [weakSelf.userPic viewWithTag:index+100];
        
        //        imageV.image = currentZoomImageView.image;
        //            [weakSelf.imageButton setImage:currentZoomImageView.image forState:UIControlStateNormal];
        
        [aImagePreviewViewController exitPreviewToRectInScreenCoordinate:[imageV1 convertRect:imageV1.frame toView:nil]];
        
    };
    self.imagePreviewViewController.imagePreviewView.currentImageIndex =  selectIndex-100;// 默认查看的图片的 index
    
    [self.imagePreviewViewController startPreviewFromRectInScreenCoordinate:[imageV convertRect:imageV.frame toView:nil] cornerRadius:imageV.layer.cornerRadius];
}




#pragma mark - <QMUIImagePreviewViewDelegate>

- (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
    return self.model.fileList.count;
}

- (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
    // 模拟异步加载的情况
    zoomImageView.reusedIdentifier = @(index);
    [zoomImageView showLoading];
    if ([zoomImageView.reusedIdentifier isEqual:@(index)]) {
        [zoomImageView hideEmptyView];
        UIImageView *imageV = [self.userPic viewWithTag:100+index];
        zoomImageView.image = imageV.image;
        
    }
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //
    //    });
}

- (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
    return QMUIImagePreviewMediaTypeImage;
}

#pragma mark - <QMUIZoomImageViewDelegate>

- (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
    //点击缩回
    self.imagePreviewViewController.customGestureExitBlock(self.imagePreviewViewController, zoomImageView);
}

-(QMUIButton *)btnLike{
    if (!_btnLike) {
        _btnLike = [[QMUIButton alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        [_btnLike setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_btnLike setImage:[UIImage imageNamed:@"ugc_详情_默认"] forState:UIControlStateNormal];
        [_btnLike setImage:[UIImage imageNamed:@"ugc_详情_已赞"] forState:UIControlStateSelected];
        @weakify(self);
        [[_btnLike rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            if (!self.btnLike.selected) {
                [[serviceDefualt loadUpdateUserLaud:self.modelLike.userUgc.ugcId laudType:@"1" reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
                    if (x.success) {
                        [Tools showTips:@"点赞成功"];
                        self.modelLike.userUgc.laudStatus = @"1";
                        self.modelLike.userUgc.laudCount =  [NSString stringWithFormat:@" %ld",[self.modelLike.userUgc.laudCount integerValue]+1];
                        if (self.likeSuccess) {
                            self.likeSuccess();
                        }
                        [self upLoadData];
                    }else{
                        if (![x.errorInfo isEqualToString:@"未登录"]) {
                            [Tools showTips:x.errorInfo];
                        }else{
//                            [Tools pushSinge];
                        }
                        self.modelLike.userUgc.laudStatus = @"0";
                        self.btnLike.selected = !self.btnLike.selected;
                    }
                }];
            } else {
                [[serviceDefualt loadUpdateUserLaud:self.modelLike.userUgc.ugcId laudType:@"2" reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
                    if (x.success) {
                        [Tools showTips:@"取消成功"];
                        self.modelLike.userUgc.laudStatus = @"0";
                        self.modelLike.userUgc.laudCount =  [NSString stringWithFormat:@" %ld",[self.modelLike.userUgc.laudCount integerValue]-1];
                        if (self.likeSuccess) {
                            self.likeSuccess();
                        }
                        [self upLoadData];
                    }else{
                        if (![x.errorInfo isEqualToString:@"未登录"]) {
                            [Tools showTips:x.errorInfo];
                        }else{
//                            [Tools pushSinge];
                        }
                        self.modelLike.userUgc.laudStatus = @"1";
                        
                        self.btnLike.selected = !self.btnLike.selected;
                    }
                }];
            }
            self.btnLike.selected = !self.btnLike.selected;
            
            
        }];
        
    }
    return _btnLike;
}

/** 更新数据 */
-(void)upLoadData{
    Ugc_Detail_VC_WX *vc = (Ugc_Detail_VC_WX *)[self getViewController:[Ugc_Detail_VC_WX class]];
    [vc loaddata];
}


-(QMUILabel *)labLike{
    if (!_labLike) {
        _labLike = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _labLike.numberOfLines = 1;
        _labLike.text = @"暂无点赞";
        _labLike.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    }
    return _labLike;
}
-(QMUILabel *)labLikeName{
    if (!_labLikeName) {
        _labLikeName = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _labLikeName.numberOfLines = 0;
        _labLikeName.font = [UIFont systemFontOfSize:14];
    }
    return _labLikeName;
}

-(BaseView *)commentNumBackGround{
    if (!_commentNumBackGround) {
        _commentNumBackGround = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 20)];
        _commentNumBackGround.backgroundColor = [UIColor colorWithHex:@"f5f5f5"];
    }
    return _commentNumBackGround;
}

-(QMUILabel *)commentNum{
    if (!_commentNum) {
        _commentNum = [[QMUILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _commentNum.numberOfLines = 1;
        _commentNum.text = @"暂无评论";
        _commentNum.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    }
    return _commentNum;
}



-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    
    paraStyle.alignment = NSTextAlignmentLeft;
    
    paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距
    
    paraStyle.hyphenationFactor = 1.0;
    
    paraStyle.firstLineHeadIndent = 0.0;
    
    paraStyle.paragraphSpacingBefore = 0.0;
    
    paraStyle.headIndent = 0;
    
    paraStyle.tailIndent = 0;
    
    //设置字间距 NSKernAttributeName:@1.5f
    
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f};
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    
    label.attributedText = attributeStr;
    

}

-(BaseLab *)TopicLab{
    if (!_TopicLab) {
        _TopicLab = [BaseLab initCustomLab:@"     1232131" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFangSC-Semibold" size:15]];
        _TopicLab.numberOfLines = 2;
        _TopicLab.lineBreakMode = NSLineBreakByCharWrapping;
        [[_TopicLab addTag]subscribeNext:^(id  _Nullable x) {
            TopicDetailViewController * vc = [[TopicDetailViewController
                                               alloc]init];
            vc.topicId = self.model.userSubjectId;
            [self.getNav pushViewController:vc animated:YES];
        }];
    }
    return _TopicLab;
}

-(BaseImageV *)TopicIcon{
    if (!_TopicIcon) {
        _TopicIcon = [[BaseImageV alloc]init];
        
        _TopicIcon.image = [UIImage imageNamed:@"发布_#话题"];
        _TopicIcon.backgroundColor = [UIColor clearColor];
    }
    return _TopicIcon;
}
@end
